﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using V5_DAL;
using V5_Model;
using V5_Common;

namespace V5_BLL
{
    public class BLLProductComment
    {
        DALProductComment dal = new DALProductComment();
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(ModelProductComment model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(ModelProductComment model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ID)
        {

            dal.Delete(ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelProductComment GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public ModelProductComment GetModelByCache(int ID)
        {

            string CacheKey = "ModelProductCommentModel-" + ID;
            object objModel = DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(ID);
                    if (objModel != null)
                    {
                        int ModelCache = ConfigHelper.GetConfigInt("ModelCache");
                        DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (ModelProductComment)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ModelProductComment> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ModelProductComment> DataTableToList(DataTable dt)
        {
            List<ModelProductComment> modelList = new List<ModelProductComment>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ModelProductComment model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ModelProductComment();
                    if (dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    model.CommentContent = dt.Rows[n]["CommentContent"].ToString();
                    model.CommentName = dt.Rows[n]["CommentName"].ToString();
                    model.CommentEmail = dt.Rows[n]["CommentEmail"].ToString();
                    model.CommentIP = dt.Rows[n]["CommentIP"].ToString();
                    model.ProductName = dt.Rows[n]["ProductName"].ToString();
                    if (dt.Rows[n]["ProductID"].ToString() != "")
                    {
                        model.ProductID = int.Parse(dt.Rows[n]["ProductID"].ToString());
                    }
                    if (dt.Rows[n]["AddDateTime"].ToString() != "")
                    {
                        model.AddDateTime = DateTime.Parse(dt.Rows[n]["AddDateTime"].ToString());
                    }
                    model.ReplyComment = dt.Rows[n]["ReplyComment"].ToString();
                    model.ReplyName = dt.Rows[n]["ReplyName"].ToString();
                    if (dt.Rows[n]["Pmost"].ToString() != "")
                    {
                        model.Pmost = int.Parse(dt.Rows[n]["Pmost"].ToString());
                    }
                    if (dt.Rows[n]["MemberID"].ToString() != "")
                    {
                        model.MemberID = int.Parse(dt.Rows[n]["MemberID"].ToString());
                    }
                    if (dt.Rows[n]["Pmost1"].ToString() != "")
                    {
                        model.Pmost1 = int.Parse(dt.Rows[n]["Pmost1"].ToString());
                    }
                    if (dt.Rows[n]["Pmost2"].ToString() != "")
                    {
                        model.Pmost2 = int.Parse(dt.Rows[n]["Pmost2"].ToString());
                    }
                    if (dt.Rows[n]["Pmost3"].ToString() != "")
                    {
                        model.Pmost3 = int.Parse(dt.Rows[n]["Pmost3"].ToString());
                    }
                    if (dt.Rows[n]["Passed"].ToString() != "")
                    {
                        model.Passed = int.Parse(dt.Rows[n]["Passed"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        #endregion  成员方法
        #region 51aspx下载
        #endregion
        public DataSet GetList(int PageSize, int PageIndex, string strWhere, ref int Recount)
        {
            Recount = Input.SetInt(this.GetList(strWhere).Tables[0].Rows.Count);
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        public void Update_Reply(ModelProductComment model)
        {
            ModelProductComment model1 = this.GetModel(model.ID);
            model1.ReplyComment = model.ReplyComment;
            model1.Passed = model.Passed;
            this.Update(model1);
        }
    }
}
